package com.example.spring.security.demo.service;

import com.example.spring.security.demo.entity.MyUserDetails;
import com.example.spring.security.demo.entity.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName UserDetailService
 * @Description
 * @Author lichuanqi
 * @Date 2022/5/14 11:27
 * @Version 1.0
 **/
@Service
public class MyUserDetailTestService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = new User();
        user.setUserName(username);
        if (user == null){
            throw new RuntimeException("用户名或密码错误");
        }
        List<String> permissions = Arrays.asList("sys:");

        return new MyUserDetails(user, permissions);
    }
}
